# -*- coding:utf-8 -*-
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from PageClass.common.boeCommon import BoeCommon
from PageClass import BasIndexPage
from Util import logger


class Class_NewIncomeStatementBoe(BasIndexPage, BoeCommon):
    def __init__(self, driver):
        super().__init__(driver)

    # 主表区-备注
    _boeAbstract = (By.ID, "boeHeader.0.boeAbstract")

    def input_boeAbstract(self, boeAbstract):
        self.clear(*self._boeAbstract)
        self.send_text(boeAbstract, *self._boeAbstract)
        logger.info("输入主表区-备注字段")

    # 主表附加区-客户
    _vendorId = (By.ID, 'boeHeaderChild.0.vendorId')

    def click_vendorId(self):
        self.click(*self._vendorId)

    # 收入明细区-订单编号
    _orderNumber = (By.ID, 'cost.0.orderNumber')

    def input_orderNumber(self, text):
        self.send_text(text, *self._orderNumber)
        logger.info("收入明细区-订单编号输入为：{}".format(text))

    # 收入明细区-收入类型
    _operationSubTypeName = (By.ID, 'cost.0.operationSubTypeId')

    def input_operationSubTypeName(self, text):
        self.lovSelectTable(text, *self._operationSubTypeName)
        logger.info("收入明细区-收入类型选择为：{}".format(text))

    # 收入明细区-利润中心
    _expenseDeptId = (By.ID, 'cost.0.expenseDeptId')

    def click_expenseDeptId(self):
        self.click(*self._expenseDeptId)

    # 收入明细区-金额
    _expenseAmount = (By.XPATH, '//div[@class="bill-area area-is-expand table cost"]//div[@title="金额"]//input[1]')

    def input_expenseAmount(self, text):
        self.driver.find_element(*(self._expenseAmount)).send_keys(str(text))
        logger.info("收入明细区-金额 输入：{}".format(text))

    # 滚动条
    _scroll = (By.XPATH, '//div[contains(@class, "area-data-scroll is-scrolling")]')

    def scrollToRight(self, *args):
        try:
            WebDriverWait(self.driver, 1).until(
                EC.visibility_of_element_located(self._scroll))
        except Exception as e:
            pass
        else:
            ele = self.find_element(*self._scroll)
            super().scrollToRight(ele)

    # 收入明细区-税额
    _taxAmount = (By.ID, 'cost.0.taxAmount')

    def input_taxAmount(self, text):
        self.send_text(text, *self._taxAmount)
        logger.info("收入明细区-利润中心选择为：{}".format(text))

    BoeSuccessMsg = (By.XPATH, '//*[@id="app"]/div/div/div[4]/div/div/div[2]/div/p')

    def getBoeSuccessMessage(self):
        # 提单成功结果页面提示语
        return self.get_elementText(*self.BoeSuccessMsg)
